package com.tadpole.music.view.activity.me;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.tadpole.music.R;
import com.tadpole.music.app.MyApplication;
import com.tadpole.music.config.Constant;
import com.tadpole.music.iView.login.RegisterIView;
import com.tadpole.music.presenter.me.LoginOutPresenter;
import com.tadpole.music.utils.NoDoubleClickListener;
import com.tadpole.music.utils.SpUtil;
import com.tadpole.music.utils.ToastUtils;
import com.tadpole.music.view.activity.MainActivity;
import com.tadpole.music.view.activity.base.BaseActivity;


/**
 * 注销账号
 * Created By 孙岩
 * on 2022/1/22
 */
public class UserCancelActivity extends BaseActivity implements RegisterIView {
    private View viewBack;
    private TextView tvTiXing;
    private TextView tvUserCancel;
    private LoginOutPresenter loginOutPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_cancel);
        initView();
        initListeners();
        loginOutPresenter = new LoginOutPresenter();
        loginOutPresenter.attachView(this);
    }

    //初始化控件
    private void initView(){
        viewBack = findViewById(R.id.viewBack);
        tvTiXing = findViewById(R.id.tvTiXing);
        tvUserCancel = findViewById(R.id.tvUserCancel);
    }

    //初始化监听器
    private void initListeners(){
        viewBack.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                UserCancelActivity.this.finish();
            }
        });


        tvUserCancel.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                loginOutPresenter.loginOut();
            }
        });
    }

    @Override
    public void showResult() {
        ToastUtils.show("注销成功");
        //清空Sp保存
        SpUtil.getInstance(UserCancelActivity.this).clear();
        SpUtil.getInstance(this).putString(Constant.FREE_COURSE,"1");
        MyApplication.getInstance().finishManager.removeAllActivity();
        Intent intent = new Intent(UserCancelActivity.this, MainActivity.class);
        startActivity(intent);
    }

    @Override
    public void show401() {

    }

//    @Override
//    public void shoCancelResult() {
//        ToastUtils.show("注销成功");
//        //清空Sp保存
//        SpUtil.getInstance(UserCancelActivity.this).clear();
//        SpUtil.getInstance(this).putString(Constant.FREE_COURSE,"1");
//        MyApplication.getInstance().finishManager.removeAllActivity();
//        Intent intent = new Intent(UserCancelActivity.this, MainActivity.class);
//        startActivity(intent);
//    }
//
//    @Override
//    public void showIsResult(boolean isCancel) {
//
//    }
}
